{% extends 'app01/base.html' %}
{% block active_case_manage %}{% endblock %}
{% block active_template %} class="active"{% endblock %}

{% block button %}
    <div class="btn-group" role="group" aria-label="Basic example">
        {% block not_in_index %}
            <button type="button" data-toggle="modal" data-target="#createTemplateModal" class="btn btn-primary">新增
            </button>
        {% endblock %}
        <button type="button" class="btn btn-primary" disabled>编辑</button>
        <button type="button" class="btn btn-primary" disabled>删除</button>
        <button type="button" class="btn btn-primary"
                onclick="window.location.href='{% block export_url %}{% endblock %}'">导出
        </button>
        <button type="button" class="btn btn-primary" onclick="window.location.reload()">刷新</button>
    </div>
{% endblock %}
{% block sub_header %}用例模板管理{% endblock %}
{% block table %}
    <table class="table table-striped table-bordered table-responsive">
        <thead>
        <tr>
            <th style="width: 10px"><input type="checkbox"></th>
            <th style="width: 50px">序号</th>
            <th nowrap="nowrap">模板名</th>
            <th nowrap="nowrap">项目名称</th>
            <th nowrap="nowrap">模块名称</th>
            <th nowrap="nowrap">页面名称</th>
            <th nowrap="nowrap">查看结果方式</th>
            <th nowrap="nowrap">创建人</th>
            <th nowrap="nowrap">创建时间</th>
            <th nowrap="nowrap">更新时间</th>
            <th nowrap="nowrap">备注</th>
            <th hidden="hidden">ID</th>
            <th nowrap="nowrap">操作</th>
        </tr>
        </thead>
        <tbody>
        {% if pages %}
            {% for element in pages %}
                <tr style="font-size: 10px">
                    <td><input type="checkbox" value="{{ element.id }}"></td>
                    <td>{{ forloop.counter }}</td>
                    <td>{{ element.template_name }}</td>
                    <td>{{ element.project_name }}</td>
                    <td>{{ element.module_name }}</td>
                    <td>{{ element.page_name }}</td>
                    <td>{{ element.check_the_result }}</td>
                    <td> {{ element.creator }}</td>
                    <td>{{ element.create_time|date:'Y-m-d H:i' }}</td>
                    <td>{{ element.update_time|date:'Y-m-d H:i' }}</td>
                    <td>{{ element.remarks }}</td>
                    <td hidden="hidden">{{ element.id }}</td>
                    <td nowrap="nowrap">
                        <button data-toggle="modal" data-target=".bs-example-modal-lg"
                                onclick="showDialog(this)">修改
                        </button>
                        <a href="{% block delete_url %}{% url 'caseTemplate:delete_template' element.id %}{% endblock %}" id="{{ element.id }}"
                           onclick="return deleteJob()">删除</a>
                    </td>
                </tr>

            {% endfor %}
        {% endif %}
        </tbody>
    </table>
{% endblock %}
{% block search %}
    <form class="form-inline"
          action="{% block search_url %}{% url 'caseTemplate:search_template' %}{% endblock search_url %}"
          id="form_Condition" method="get">
        {% csrf_token %}
        <label for="startTime">创建起始：</label>
        <input type="date" class="form-control input-sm" id="start_date" name="start_date"
                {% block search_start %}{% endblock %}
               style="width: 165px;margin-right: 5px">
        <label for="endTime">创建结束：</label>
        <input type="date" class="form-control input-sm" id="end_date" name="end_date"
                {% block search_end %}{% endblock %} style="width: 165px;margin-right: 5px">
        {% block search_condition %}
            <label for="template_name">模板名称：</label>
            <input class="form-control" id="template_name" name="template_name"
                    {% block template_name %}{% endblock %} style="width: 120px;margin-right: 5px">{% endblock %}
        <label for="project_name">项目名称：</label>
        <input class="form-control" id="project_name" name="project_name"
                {% block project_name %}{% endblock %} style="width: 120px;margin-right: 5px">
        <br/>
        <br/>
        <div class="btn-group">
            <button type="button" class="btn btn-secondary btn-sm" id="btn_Clear" onclick="function back_to_index() {
                    window.location.href='{% block back_url %}{% endblock %}';
                    }
                    back_to_index()">清空
            </button>
            <button type="submit" class="btn btn-info btn-sm" id="btn_Search">查询
            </button>
        </div>
    </form>
{% endblock %}
{% block edit_modal %}
    <div class="modal fade" id="EditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="EditModalLabel">模板修改</h4>
                </div>
                <form class="form-inline"
                      action="{% block edit_url %}{% url 'caseTemplate:edit_template' %}{% endblock %}" method="post">
                    {% csrf_token %}
                    <div class="modal-body">
                        <label style="width: 70px" for="template_id">ID：</label>
                        <input name="template_id" class="form-control input_for_modal template_id" type="text"
                               id="template_id" value="1" readonly>
                        <label for="template_name" style="width: 70px;">模板名：</label>
                        <input name="template_name" class="form-control input_for_modal template_name"
                               type="text" id="template_name" style="width: 192px" required>
                        <label for="project_name">项目名称：</label>
{#                        <select class='form-control' required#}
{#                                style='margin-bottom: 2px; margin-top: 2px; height: 32px; width: 203px;'#}
{#                                name='template_name'#}
{#                                id='template_name'>#}
{#                            {% for project in projects %}#}
{#                                <option value="{{ project.project_name }}">{{ project.project_name }}</option>#}
{#                            {% endfor %}#}
{#                        </select>#}
                        <input class='form-control project_name' readonly style='width: 191px;' type="text" name='project_name' id='project_name'>

                    <label for="module_name" style="width: 70px">模块名称：</label>
                        <input class='form-control module_name' placeholder="多(三)级模块英文逗号分隔" style='width: 191px;' type="text" name='module_name' id='module_name'>
                    <label for="page_name" style="width: 70px">页面名称：</label>
                        <input class='form-control page_name' style='width: 191px'  name='page_name' id='page_name'>
                    <label for="check_result_method" style="width: 70px">查看结果方式：</label>
{#                        <select class='form-control' required#}
{#                                style='margin-bottom: 2px; margin-top: 2px; height: 32px; width: 191px' name='check_result_method' id='check_result_method'>#}
{#                                <option value="数据库查看">数据库查看</option>#}
{#                                <option value="页面查看">页面查看</option>#}
{#                        </select>#}
                        <input class='form-control check_the_result' style='width: 191px;' type="text" name='check_the_result' id='check_the_result'>

                    <label style="width: 70px" for="creator">创建人：</label>
{#                        <select class='form-control' required style='margin-bottom: 2px; margin-top: 2px; height: 34px; width: 196px' name='creator' id='creator' >#}
{#                            {% for user in users %}#}
{#                                <option value="{{ user.user_name }}">{{ user.user_name }}</option>#}
{#                            {% endfor %}#}
{#                        </select>#}
                        <input class='form-control creator' readonly style='width: 191px;' type="text" name='creator' id='creator'>

                        <label style="width: 70px" for="create_time">创建时间：</label>
                        <input name="create_time" class="form-control input_for_modal create_time"
                               type="datetime-local" style="width: 193px;" id="create_time" readonly>
                        <label style="width: 70px" for="remarks">备注：</label>
                        <input name="remarks" class="form-control input_for_modal remarks" type="text"
                               id="remarks">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}
{% block edit_script %}
    <script>
        function showDialog(obj) {
            $('#EditModal').modal('show');
            var tds = $(obj).parent().parent().find('td');
            $(".template_name").val($(tds.eq(2)).text());
            $(".project_name").val($(tds.eq(3)).text());

            $(".module_name").val($(tds.eq(4)).text());
            $(".page_name").val($(tds.eq(5)).text());
            $(".check_the_result").val($(tds.eq(6)).text());
            $(".creator").val($(tds.eq(7)).text());


            var create_time = $(tds.eq(8).text()).selector
            var create_time1 = create_time.split(' ').join('T')
            $(".create_time").val(create_time1);
            $(".remarks").val($(tds.eq(10)).text());
            $(".template_id").val($(tds.eq(11)).text());
        }

        function deleteJob() {
            return confirm("确定要删除吗?");
        }

    </script>
{% endblock %}
{% block create_modal %}
    <div class="modal fade" id="createTemplateModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">模板新增</h4>
                </div>
                <form class="form-inline" action="
                        {% block create_case_url %}{% url 'caseTemplate:create_template' %}{% endblock create_case_url %}"
                      method="post">
                    {% csrf_token %}
                    <div class="modal-body">
                        <label for="template_name" style="width: 70px">模板名称：</label>
                        <input name="template_name" class="form-control input_for_modal" type="text"
                               id="template_name" required style="width: 191px;">
                        <label for="project_name" style="width: 70px">项目名称：</label>
                        <select class='form-control' required style='margin-bottom: 2px; margin-top: 2px; height: 32px; width: 191px'
                                name='project_name' id='project_name'>
                            {% for project in projects %}
                                <option value="{{ project.project_name }}">{{ project.project_name }}</option>
                            {% endfor %}
                        </select>
                    <label for="module_name" style="width: 70px">模块名称：</label>
                        <input class='form-control' placeholder="多(三)级模块英文逗号分隔" style='width: 191px;' type="text" name='module_name' id='module_name'>
                    <label for="page_name" style="width: 70px">页面名称：</label>
                        <input class='form-control' style='width: 191px'  name='page_name' id='page_name'>
                    <label for="check_result_method" style="width: 70px">查看结果方式：</label>
                        <select class='form-control' required
                                style='margin-bottom: 2px; margin-top: 2px; height: 32px; width: 191px' name='check_result_method' id='check_result_method'>
                                <option value="数据库查看">数据库查看</option>
                                <option value="页面查看">页面查看</option>
                        </select>
                    <label style="width: 70px" for="creator">创建人：</label>
                                            <select class='form-control' required style='margin-bottom: 2px; margin-top: 2px; height: 34px; width: 196px' name='creator' id='creator' >
                                                {% for user in users %}
                                                    <option value="{{ user.user_name }}">{{ user.user_name }}</option>
                                                {% endfor %}
                                            </select>
                        <label for="create_time">创建时间：</label>
                        <input name="create_time" style="width: 191px" required class="form-control input_for_modal" type="datetime-local" id="create_time">
                        <br>
                        <label style="width: 70px" for="remarks">备注：</label>
                        <input name="remarks" style="width: 191px;" class="form-control input_for_modal" type="text"
                               id="remarks">
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}